package io;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

public class Demo5 {
    public static void main1(String[] args) throws IOException {
        InputStream inputStream=new FileInputStream("C:/test/text.txt");
        while (true) {
            int n = inputStream.read();
            if (n == -1) {
                // 读取到文件末尾了. 读取完毕
                break;
            }
            // 打印字节, 习惯于使用十六进制.
            System.out.printf("%x\n", n);
        }
    }

    public static void main(String[] args) throws IOException {
        InputStream inputStream=new FileInputStream("c:/test/text.txt");
        while (true){
            byte[] bytes=new byte[1024];
            int n=inputStream.read(bytes);
            if (n==-1){
                break;
            }
            for (int i = 0; i < n; i++) {
                System.out.printf("%x\n", bytes[i]);
            }

        }
    }
}
